#include "Histogram.h"

int histo[256];

void histogram(LPBYTE sImg) {
  int i;
  for (i = 0; i < IMG_SIZE; i++)
    histo[sImg[i]]++;
}

void histoStretching(LPBYTE sImg) {
  int min = 255;
  int max = 0;
  int i;

  for (i = 0; i < 256; i++) {
    if (histo[i] != 0) {
      min = i;
      break;
    }
  }

  for (i = 255; i >= 0; i--) {
    if (histo[i] != 0) {
      max = i;
      break;
    }
  }

  for (i = 0; i < IMG_SIZE; i++) {
    sImg[i] = (BYTE) (((sImg[i] - min) / (double) (max - min)) * 255.0);
  }
}
